package org.jeecg.access.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.access.constant.PlatformType;
import org.jeecg.access.entity.AccountData;
import org.jeecg.access.entity.PlatformTotal;
import org.jeecg.access.entity.WorkData;
import org.jeecg.access.platform.mapper.WbCountMapper;
import org.jeecg.access.service.UnifiedPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description: 微博数据统计服务实现类
 * @author: taogang
 * @date: 2025/7/25 10:17
 */
@Slf4j
@Service
public class WbCountDataServiceImpl extends AbstractCountDataService implements UnifiedPlatformService {

    private final WbCountMapper wbCountMapper;

    @Autowired
    public WbCountDataServiceImpl(WbCountMapper wbCountMapper) {
        this.wbCountMapper = wbCountMapper;
    }

    @Override
    public PlatformTotal getAccountTotal() {
        PlatformTotal platformTotal = new PlatformTotal();
        try {
            PlatformTotal result = wbCountMapper.getAccountNum();
            if (result != null) {
                platformTotal = result;
            }
            platformTotal.setPlatformSign(PlatformType.WEIBO.getCode());
            platformTotal.setReadCount(0);
        } catch (Exception e) {
            log.error("获取微博账号统计数据失败", e);
        }
        return platformTotal;
    }

    @Override
    public Object getPlatformTotal() {
        AccountData result = new AccountData();
        try {
            AccountData data = wbCountMapper.getPlatformTotal();
            if (data != null) {
                result = data;
            }
        } catch (Exception e) {
            log.error("获取平台总计数据失败", e);
        }
        return result;
    }

    @Override
    protected List<AccountData> queryAccountData() {
        return wbCountMapper.getPlatformDetails();
    }

    @Override
    protected List<WorkData> queryWorksData() {
        return wbCountMapper.getWorksList();
    }

    @Override
    public String getPlatformTypeCode() {
        return PlatformType.WEIBO.getCode();
    }
}